<template>
  <div>
    <div class="ta-search-box">
      <el-form ref="searchForm" :inline="true" :model="searchForm">
        <el-form-item label="算法">
          <el-select v-model="searchForm.type" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否评论">
          <el-select v-model="searchForm.status" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="是否加急">
          <el-select v-model="searchForm.urgent" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in urgentOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item class="text-right">
          <el-button type="primary" @click="handSubmit('form')">
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="ta-search-box">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :row-key="
          (row) => {
            return row.recordId;
          }
        "
      >
        <el-table-column prop="date" label="日期"></el-table-column>
        <el-table-column
          :key="0"
          prop="type"
          label="算法类型"
          :formatter="formatterType"
        ></el-table-column>
        <el-table-column
          v-if="searchForm.type == 0"
          :key="1"
          prop="finPic"
          label="指纹图像"
        >
          <template slot-scope="scope">
            <img
              :src="scope.row.finPic"
              alt
              style="display: block; height: 100px; max-width: 100px"
            />
          </template>
        </el-table-column>
        <el-table-column
          :key="2"
          v-if="searchForm.type == 1"
          prop="fakePic"
          label="笔迹图像1"
        >
          <template slot-scope="scope">
            <img
              :src="scope.row.fakePic"
              alt
              style="display: block; height: 100px; max-width: 100px"
            />
          </template>
        </el-table-column>
        <el-table-column
          :key="3"
          v-if="searchForm.type == 1"
          prop="realPic"
          label="笔迹图像2"
        >
          <template slot-scope="scope">
            <img
              :src="scope.row.realPic"
              alt
              style="display: block; height: 100px; max-width: 100px"
            />
          </template>
        </el-table-column>
        <el-table-column
          :key="4"
          v-if="searchForm.type == 0"
          prop="isTrue"
          label="真假結果"
          :formatter="formatterResult"
          width="80"
        >
        </el-table-column>
        <el-table-column
          :key="5"
          v-if="searchForm.type == 0"
          prop="rate"
          label="假指纹概率"
          width="120"
        >
        </el-table-column>
        <el-table-column
          v-if="searchForm.type == 1"
          :key="12"
          prop="rate"
          label="笔迹相似度"
          width="120"
        >
        </el-table-column>
        <el-table-column :key="6" prop="comment" label="专家评论" width="180">
        </el-table-column>
        <el-table-column
          :key="7"
          v-if="searchForm.type == 0"
          prop="finResult"
          label="专家鉴定指印结果"
          :formatter="formatterFinResult"
        >
        </el-table-column>
        <el-table-column
          v-else
          :key="8"
          prop="signResult"
          label="专家鉴定签名结果"
          :formatter="formatterSignResult"
        >
        </el-table-column>
        <el-table-column :key="9" align="left" fixed="right" label="操作">
          <template #default="scope">
            <el-button
              icon="el-icon-delete"
              size="small"
              type="text"
              @click="deleteRecord(scope.row)"
              >删除记录</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="ta-pagination">
      <el-pagination
        :current-page="page"
        :page-size="pageSize"
        :page-sizes="[5, 10, 20, 50]"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>

<script>
import {
  queryIdentRecordByAdmin,
  deleteIdentRecordByExpert,
} from "@/api/modules/fingerprint";
import Constants from "@/constants";
export default {
  name: "finRecord",
  data() {
    return {
      searchForm: {
        userid: 0,
        type: 0,
        status: 0,
        pagenum: 1,
        pagesize: 5,
      },
      tableData: [],
      roleValue: 2,
      typeOptions: [
        {
          value: 0,
          label: "指纹算法",
        },
        {
          value: 1,
          label: "笔迹算法",
        },
      ],
      statusOptions: [
        {
          value: 0,
          label: "全部",
        },
        {
          value: 1,
          label: "已评论",
        },
        {
          value: 2,
          label: "未评论",
        },
      ],
      urgentOptions: [
        {
          value: 0,
          label: "全部",
        },
        {
          value: 1,
          label: "加急",
        },
      ],
      page: 1,
      pageSize: 5,
      total: 0,
    };
  },
  created() {
    this.queryTableData();
  },
  methods: {
    queryTableData() {
      this.searchForm.adminId = localStorage.getItem("userId");
      this.searchForm.pagenum = this.page;
      this.searchForm.pagesize = this.pageSize;

      queryIdentRecordByAdmin(this.searchForm).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.tableData = res.obj;
          this.total = res.obj[0].count;
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
    deleteRecord(row) {
      console.log(row);
      let params = {
        recordId: row.recordId,
        userid: localStorage.getItem("userId"),
      };
      deleteIdentRecordByExpert(params).then((res) => {
        if (res.code == 200) {
          this.queryTableData();
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
    handleCurrentChange(page) {
      this.page = page;
      this.queryTableData();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.queryTableData();
    },
    handleClick(row) {
      console.log(row);
    },
    handleAppraisal() {
      this.$router.push({ path: "/appraisal" });
    },
    handSubmit() {
      this.queryTableData();
    },
    formatterFinResult(row, column) {
      if (row.finResult == 0) {
        return "假";
      } else if (row.finResult == 1) {
        return "真";
      } else {
        return "";
      }
    },
    formatterSignResult(row, column) {
      if (row.signResult == 0) {
        return "假";
      } else if (row.signResult == 1) {
        return "真";
      } else {
        return "";
      }
    },
    formatterResult(row, column) {
      if (row.isTrue == 0) {
        return "假";
      } else if (row.isTrue == 1) {
        return "真";
      } else {
        return "";
      }
    },
    formatterType(row, column) {
      if (row.type == 0) {
        return "指纹算法";
      } else if (row.type == 1) {
        return "笔迹算法";
      } else {
        return "";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
h1 {
  padding-top: 25px;
  padding-bottom: 25px;
}
</style>
